{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function loads in module json:\n",
      "\n",
      "loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)\n",
      "    Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance\n",
      "    containing a JSON document) to a Python object.\n",
      "    \n",
      "    ``object_hook`` is an optional function that will be called with the\n",
      "    result of any object literal decode (a ``dict``). The return value of\n",
      "    ``object_hook`` will be used instead of the ``dict``. This feature\n",
      "    can be used to implement custom decoders (e.g. JSON-RPC class hinting).\n",
      "    \n",
      "    ``object_pairs_hook`` is an optional function that will be called with the\n",
      "    result of any object literal decoded with an ordered list of pairs.  The\n",
      "    return value of ``object_pairs_hook`` will be used instead of the ``dict``.\n",
      "    This feature can be used to implement custom decoders.  If ``object_hook``\n",
      "    is also defined, the ``object_pairs_hook`` takes priority.\n",
      "    \n",
      "    ``parse_float``, if specified, will be called with the string\n",
      "    of every JSON float to be decoded. By default this is equivalent to\n",
      "    float(num_str). This can be used to use another datatype or parser\n",
      "    for JSON floats (e.g. decimal.Decimal).\n",
      "    \n",
      "    ``parse_int``, if specified, will be called with the string\n",
      "    of every JSON int to be decoded. By default this is equivalent to\n",
      "    int(num_str). This can be used to use another datatype or parser\n",
      "    for JSON integers (e.g. float).\n",
      "    \n",
      "    ``parse_constant``, if specified, will be called with one of the\n",
      "    following strings: -Infinity, Infinity, NaN.\n",
      "    This can be used to raise an exception if invalid JSON numbers\n",
      "    are encountered.\n",
      "    \n",
      "    To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``\n",
      "    kwarg; otherwise ``JSONDecoder`` is used.\n",
      "    \n",
      "    The ``encoding`` argument is ignored and deprecated.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import json\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "dict_sample = {\"username\": \"Username\", \"password\": \"123456\"}\n",
    "with open('sample.json','w') as fp:\n",
    "    json.dump(dict_sample,fp,indent = 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fp.write()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'username': 'Username', 'password': '123456'}\n",
      "Username 123456\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "with open('sample.json','r') as fp:\n",
    "    dict_sample = json.load(fp)\n",
    "    \n",
    "print(dict_sample)\n",
    "print(dict_sample['username'],dict_sample['password'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
